/******************************************************************************************
 * Import
 ******************************************************************************************/

// module
import Taro, { Component } from '@tarojs/taro'

// project
import { CPage, CContent, CHeader, CFooter, CFloat, CAround, CBetween, CCenter, CRow, CColumn, CWrap, CLine, CHand, CItemX, CItemY, CText, CLabel, CSvg, CImage, CButton } from '../../../library/comp';
import { Base64, Gen, Time, Zip, Session, Storage, Http } from '../../../library/func';
import Icon from '../../../project/style/icon';
import DoHttp from '../../../project/func/http/http';

/******************************************************************************************
 * Export Class
 ******************************************************************************************/

export default class Settlement extends Component {

	/*------------------------------------------------------------------------------------
	 * 初始化
	 *-----------------------------------------------------------------------------------*/
	constructor(props) {
		super(props);

		/**
		 * state
		 */
		this.state = {
			id:1,
			data:{
				// 屏幕高度
				scrollHeight: wx.getSystemInfoSync().windowHeight,
				order:{}
			},
		}
	}

	/*------------------------------------------------------------------------------------
	 * 生命周期
	 *-----------------------------------------------------------------------------------*/
	// willMount
	componentWillMount() {
		this.setState({
			id:this.$router.params.id
		})
	}
	// didMount
	componentDidMount() {
		DoHttp.get({
			url:'order/detail.php',
			data:{
				id:this.state.id
			},
			success: (data) => {
				this.setState({
					data:data
				},()=>{
					console.log('**********************',this.state.data)
				})
				console.log('data===============================================>',data)
			}
		})

	}
	
	/*------------------------------------------------------------------------------------
	 * 事件处理
	 *-----------------------------------------------------------------------------------*/
	// onClick
	onClick = (id, e)=> {
		console.log('onClick: ' + id)
    }
    
    // onRedirect
    onRedirect = (url, e)=> {
        wx.redirectTo({
            url: url
        })
    }


	/*------------------------------------------------------------------------------------
	 * 自定义方法
	 *-----------------------------------------------------------------------------------*/
	// 时间戳转字符串
	timeToString = (time,e) => {
		if(time){
			console.log('time::::',time)
			let date = new Date(time*1000);
			let year = date.getFullYear();
			let month = date.getMonth()+1;
			let day = date.getDate();
			let hours = date.getHours();
			let minutes = date.getMinutes();
			let seconds = date.getSeconds();
			console.log('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$',year+'-'+month+'-'+day+' '+hours+':'+minutes+':'+seconds)
			return year+'-'+month+'-'+day+' '+hours+':'+minutes+':'+seconds;
		}
	}

	config = {
        navigationBarTitleText: '商品结算详情',
        navigationBarBackgroundColor: '#dd2f3c',
        navigationBarTextStyle: '#fff'
    }

	/*------------------------------------------------------------------------------------
	 * 渲染
	 *-----------------------------------------------------------------------------------*/
	render () {
		return (
			<CPage>
				<CContent bg='#fff' h={this.state.scrollHeight + 'rpx'}>
					
					{/* 表单 */}
					<CColumn>
						<CRow py='26' mx='24' bb='1 solid #d2d1d1'>
							<CText color='#757575' size='30' class='f03'>商品名称</CText>
							<CHand color='#292929' size='28' class='f07'>{this.state.data.order.object.set_order_name}</CHand>
						</CRow>
						<CRow py='26' mx='24' bb='1 solid #d2d1d1'>
							<CText color='#757575' size='30' class='f03'>订单号</CText>
							<CHand color='#292929' size='28' class='f07'>{this.state.data.order.set_orderid}</CHand>
						</CRow>
						<CRow py='26' mx='24' bb='1 solid #d2d1d1'>
							<CText color='#757575' size='30' class='f03'>订单状态</CText>
							<CHand color='#292929' size='28' class='f07'>{this.state.data.order.enum_status}</CHand>
						</CRow>
						<CRow py='26' mx='24' bb='1 solid #d2d1d1'>
							<CText color='#757575' size='30' class='f03'>价格</CText>
							<CHand color='#292929' size='28' class='f07'>{this.state.data.order.set_amount}</CHand>
						</CRow>
						<CRow py='26' mx='24' bb='1 solid #d2d1d1'>
							<CText color='#757575' size='30' class='f03'>佣金比</CText>
							<CHand color='#292929' size='28' class='f07'>{this.state.data.order.set_commission / this.state.data.order.set_amount * 100}%</CHand>
						</CRow>
						<CRow py='26' mx='24' bb='1 solid #d2d1d1'>
							<CText color='#757575' size='30' class='f03'>预估收入</CText>
							<CHand color='#292929' size='28' class='f07'>{this.state.data.order.set_commission}</CHand>
						</CRow>
						<CRow py='26' mx='24' bb='1 solid #d2d1d1'>
							<CText color='#757575' size='30' class='f03'>订单支付时间</CText>
							<CHand color='#292929' size='28' class='f07'>{this.timeToString.bind(this,this.state.data.order.time_pay)()}</CHand>
						</CRow>
						<CRow py='26' mx='24' bb='1 solid #d2d1d1'>
							<CText color='#757575' size='30' class='f03'>订单收货时间</CText>
							<CHand color='#292929' size='28' class='f07'>{this.timeToString.bind(this,this.state.data.order.time_completed)()}</CHand>
						</CRow>
						<CRow py='26' mx='24' bb='1 solid #d2d1d1'>
							<CText color='#757575' size='30' class='f03'>结算时间</CText>
							<CHand color='#292929' size='28' class='f07'>{this.timeToString.bind(this,this.state.data.order.time_completed)()}</CHand>
						</CRow>
					</CColumn>
					

					{/* 说明 */}
					<CColumn mt='60' px='16'>
						<CColumn rel x='center' y='center' h='40' lh='40' bb='2 #e0c6a0' mb='32' >
							<CHand class='settlemetLine'></CHand>
							<CText w='200' size='30' rel zIndex='1' bg='#fff' x='center' mt='10' color='#dcab58'>说明</CText>
						</CColumn>
						<CText color='#dcab58' mb='4' lh='40'>1. 只要买家下单付款了在这里就可以看到实时对应数据,若订单正常结算,则预估收入将在结算时正常打入您的账户,如用户购买后发起退款退货并成功,佣金将不会结算。</CText>
						<CText color='#dcab58' mb='4' lh='40'>2. 买家主动确认收货的时间点为确认收货时间,如买家未主动确认收货,在发货后10天,系统会自动将订单设置为确认收货。</CText>
						<CText color='#dcab58' mb='100' lh='40'>3. 买家确认收货后,9天内末发生退款退货,订单可结算,结算时佣金打入您的佣金账户。</CText>
					</CColumn>

				</CContent>
			</CPage>
		)
	}
}


